<template>
	<view>
		<view class="QAbox">
			<view class="QAcontent">
				<view class="top">
					<view class="QAtitle">
						{{data.title}}
					</view>
					<view class="QAcourse">
						<view class="weight">
							所属课程:
						</view>
						{{data.courseName}}
					</view>
				</view>
				<view class="main">
					<view class="text">
						<u-parse :html="data.content"></u-parse>
					</view>
				</view>
				<view class="bottom">
					<view class="icons">
						<view class="edit" @click="edit(data)">
							<u-icon name="edit-pen-fill"></u-icon>编辑
						</view>
						<view class="delete" @click="deleteQA(data)">
							<u-icon name="trash-fill"></u-icon>删除
						</view>
						<view class="detail" @click="toDetail(data)">
							<u-icon name="chat-fill"></u-icon>回答{{data.totalQue}}
						</view>
					</view>
					<view class="time">
						{{data.createTime}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectFlag: false
			}
		},
		methods: {
			toDetail(data) {
				if (!this.selectFlag) {
					this.$u.route('pages/course/QAdetail/QAdetail', data);
				}
			},
			cardSelected() {
				this.selectFlag = !this.selectFlag
			},
			edit(data) {
				if (!this.selectFlag) {
					this.$emit('edit', data);
				}
			},
			deleteQA(data) {
				if (!this.selectFlag) {
					this.$emit('deleteQA', data);
				}
			}
		},
		props: {
			data: {
				type: Object,
				default () {
					return {}
				}
			}
		},
		onReady: function(option) { //option为object类型，会序列化上个页面传递的参数
			console.log(option); //打印出上个页面传递的参数。
		}
	}
</script>

<style lang="scss">
	.QAbox {
		background-color: white;
		box-sizing: border-box;
		padding: 10rpx 10rpx 10rpx 10rpx;
		box-sizing: border-box;
		margin: 10px;
		box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.1);
		border-radius: 5px;

		.QAcontent {
			display: flex;
			flex-direction: column;

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.QAtitle {
					font-weight: bold;
				}

				.QAcourse {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.weight {
						font-weight: bold;
					}
				}
			}

			.main {
				box-sizing: border-box;
				padding: 10rpx 5rpx 0rpx 5rpx;
				width: 100%;
				display: -webkit-box;
				overflow: hidden;
				text-overflow: ellipsis;
				word-wrap: break-word;
				white-space: normal !important;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				margin-bottom: 10rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;

				.icons {
					color: #0074D1;
					display: flex;
					flex-direction: row;

					.edit {
						box-sizing: border-box;
						padding-right: 10rpx;
					}

					.delete {
						box-sizing: border-box;
						padding: 0 10rpx 0 10rpx;
						border-left: 1rpx solid black;
						border-right: 1rpx solid black;
					}

					.detail {
						box-sizing: border-box;
						padding-left: 10rpx;
					}
				}

				.time {
					color: #BED3ED;
				}
			}
		}
	}
</style>
